<!-- Parent.svelte -->
 <!-- 兄弟间如何传值 -->
<script>

  import Brother1 from '../components/Brother1.svelte';
  import Brother2 from '../components/Brother2.svelte';

  import { sharedData } from '../stores/index.js';

  sharedData.subscribe(value => {
   console.log("订阅sharedData的值：",value)
  });

  // 父组件也可以监听子组件事件，更新共享数据
  function updateDataFromBrother1(data) {
    sharedData.set(data);
  }

  function updateDataFromBrother2(data) {
    sharedData.set(data);
  }
</script>

<!-- 将 sharedData 传递给两个兄弟组件 -->
<Brother1 {sharedData} on:update={updateDataFromBrother1} />
<Brother2 {sharedData} on:update={updateDataFromBrother2} />
